<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        let arrUndefined = [1, undefined, undefined, undefined];
        let filterItems = arrUndefined.filter(function (value) {
            // 返回元素和指定元素不相等的元素
            return value != undefined;
        })
        console.log(filterItems)

        function remove(arr, item) {
            //定义一个空数组
            var newarr = [];
            for (var i = 0; i < arr.length; i++) {
                // 判断原数组的元素不等于指定元素
                if (arr[i] != item) {
                    // 把元素添加到新的数组
                    newarr.push(arr[i]);
                }
            }
            console.log(newarr)
            // 返回新数组
            return newarr;
        }
        remove(arrUndefined, undefined)
       
    </script>
</body>

</html>